<template>
  <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
    <div class="site-navbar__header">
      <img src="~@/assets/img/common/light.png" class="header-light" v-show="!sidebarFold">
      <h1 class="site-navbar__brand" @click="$router.push({ name: 'home' })">
        <a class="site-navbar__brand-lg"><img class="logo" src="~@/assets/img/logo.jpg" style="height: 50px; margin:0 20px">污水收运管理系统</a>
        <!-- <a class="site-navbar__brand-mini"><img class="logo" src="~@/assets/img/login/logo-3d.gif" style="height: 60px;"></a> -->
        <!-- <a class="site-navbar__brand-mini"><img class="logo" src="../../../static/img/login/loginheader.png" style="height: 60px;"></a> -->
      </h1>
    </div>
    <div class="site-navbar__body clearfix" style="margin-left:300px">
      <div class="nav-item" @click="sidebarFold = !sidebarFold">
        <i class="el-icon-bottom-right" v-if="sidebarFold"></i>
        <i class="el-icon-bottom-left" v-else></i>
      </div>
      <div class="nav-item" @click="refresh()">
        <i class="el-icon-refresh"></i>
      </div>
      <div style="float: right; padding: 14px;">
        <el-popover
          placement="bottom"
          width="130"
          popper-class="nav-popover"
          trigger="hover">
          <span slot="reference" style="color: #fff; cursor: pointer;">
            <img src="~@/assets/img/common/close.png" style="height: 32px;">
            {{ userName }}
          </span>
          <div class="nav-popover-item" @click="updatePasswordHandle()">
            <i style="font-size: 16px;" class="iconfont iconpassword"></i>
            <span style="margin-left: 4px; font-size: 14px !important;">修改密码</span>
          </div>
          <div class="nav-popover-item" @click="logoutHandle()">
            <i style="font-size: 16px;" class="iconfont iconconditions"></i>
            <span style="margin-left: 4px; font-size: 14px !important;">退出</span>
          </div>
        </el-popover>
      </div>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
  </nav>
</template>

<script>
import UpdatePassword from './main-navbar-update-password'
import { clearLoginInfo } from '@/utils'
export default {
  inject: ['refresh'],
  data () {
    return {
      updatePassowrdVisible: false
    }
  },
  components: {
    UpdatePassword
  },
  computed: {
    navbarLayoutType: {
      get () { return this.$store.state.common.navbarLayoutType }
    },
    sidebarFold: {
      get () { return this.$store.state.common.sidebarFold },
      set (val) { this.$store.commit('common/updateSidebarFold', val) }
    },
    mainTabs: {
      get () { return this.$store.state.common.mainTabs },
      set (val) { this.$store.commit('common/updateMainTabs', val) }
    },
    userName: {
      get () { return this.$store.state.user.name }
    }
  },
  methods: {
    // 修改密码
    updatePasswordHandle () {
      this.updatePassowrdVisible = true
      this.$nextTick(() => {
        this.$refs.updatePassowrd.init()
      })
    },
    // 退出
    logoutHandle () {
      this.$confirm(`确定进行[退出]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/sys/logout'),
          method: 'post',
          data: this.$http.adornData()
        }).then(({data}) => {
          if (data && data.code === 0) {
            clearLoginInfo()
            this.$router.push({ name: 'login' })
          }
        })
      }).catch(() => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.nav-item {
  display: inline-block;
  line-height: 60px;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  margin-left: 16px;
}
.header-light {
  width: 250px;
  position: absolute;
  left: 0;
  bottom: -2px;
  animation: beamScaleAnimation 5s infinite;
}

@keyframes beamScaleAnimation
{
  0% {
    transform: scale(1); /*开始为原始大小*/
    opacity: 1;
  }
  25% {
    transform: scale(1.05); /*放大1.1倍*/
    opacity: 1;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
  75% {
    transform: scale(0.95);
    opacity: 0.9;
  }
}
</style>

<style lang="scss">
.nav-popover {
  background: rgba($color: #021730, $alpha: 0.9);
  // border: 0;
  .nav-popover-item {
    margin: 10px;
    height: 22px;
    line-height: 22px;
    color: #fff;
    cursor: pointer;
    &:hover {
      color: #00CCFF;
    }
  }
  .nav-popover-item + .nav-popover-item {
    margin-top: 16px;
  }
}
</style>